
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jQuery EasyUI 加载等待效果</title>
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css">
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
    <style>
        .loading-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 9999;
            display: none;
        }
        
        .loading-container {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: white;
            border-radius: 8px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
            text-align: center;
            min-width: 200px;
        }
        
        .spinner {
            width: 50px;
            height: 50px;
            border: 4px solid #f3f3f3;
            border-top: 4px solid #3498db;
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin: 0 auto 15px;
        }
        
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
        .loading-text {
            color: #333;
            font-weight: 500;
            margin-bottom: 0;
        }
        
        .progress-bar {
            width: 100%;
            height: 6px;
            background: #e0e0e0;
            border-radius: 3px;
            margin-top: 15px;
            overflow: hidden;
        }
        
        .progress-fill {
            height: 100%;
            background: linear-gradient(90deg, #3498db, #2980b9);
            width: 0%;
            transition: width 0.3s ease;
        }
    </style>
</head>
<body class="bg-gray-100">
    <div class="container mx-auto p-8">
        <h1 class="text-3xl font-bold text-gray-800 mb-6">jQuery EasyUI 加载等待效果演示</h1>
        
        <div class="bg-white rounded-lg shadow-md p-6 mb-6">
            <h2 class="text-xl font-semibold mb-4">功能演示区域</h2>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
                <button id="showLoading" class="bg-blue-500 hover:bg-blue-600 text-white py-2 px-4 rounded transition duration-200">
                    显示加载效果
                </button>
                
                <button id="showLoadingWithText" class="bg-green-500 hover:bg-green-600 text-white py-2 px-4 rounded transition duration-200">
                    显示带文字的加载效果
                </button>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <button id="showProgressLoading" class="bg-purple-500 hover:bg-purple-600 text-white py-2 px-4 rounded transition duration-200">
                显示进度条加载效果
                </button>
                
                <button id="hideLoading" class="bg-red-500 hover:bg-red-600 text-white py-2 px-4 rounded transition duration-200">
                隐藏加载效果
                </button>
            </div>
        </div>
        
        <div class="bg-white rounded-lg shadow-md p-6">
            <h2 class="text-xl font-semibold mb-4">EasyUI 组件演示</h2>
            
            <div class="mb-4">
                <label class="block text-gray-700 mb-2">选择操作：</label>
            <select id="operationSelect" class="easyui-combobox" style="width:200px;">
                <option value="loadData">加载数据</option>
                <option value="processForm">处理表单</option>
                <option value="ajaxRequest">发送AJAX请求</option>
            </select>
            </div>
            
            <button id="easyuiOperation" class="bg-indigo-500 hover:bg-indigo-600 text-white py-2 px-4 rounded transition duration-200">
                执行操作
            </button>
        </div>
    </div>

    <!-- 加载等待效果容器 -->
    <div id="loadingOverlay" class="loading-overlay">
        <div class="loading-container">
            <div class="spinner"></div>
            <p id="loadingMessage" class="loading-text">加载中，请稍候...</p>
            <div id="progressBar" class="progress-bar" style="display: none;">
                <div id="progressFill" class="progress-fill"></div>
            </div>
        </div>
    </div>

    <script>
        // 初始化加载效果控制对象
        const LoadingManager = {
            // 显示基本加载效果
            show: function(message = '加载中，请稍候...') {
                $('#loadingMessage').text(message);
                $('#loadingOverlay').fadeIn(300);
                $('#progressBar').hide();
            },
            
            // 显示带进度条的加载效果
            showWithProgress: function(message = '加载中，请稍候...') {
                $('#loadingMessage').text(message);
                $('#loadingOverlay').fadeIn(300);
                $('#progressBar').show();
                this.updateProgress(0);
            },
            
            // 更新进度条
            updateProgress: function(percentage) {
                $('#progressFill').css('width', percentage + '%');
            },
            
            // 隐藏加载效果
            hide: function() {
                $('#loadingOverlay').fadeOut(300);
            },
            
            // 模拟耗时操作
            simulateOperation: function(operationName, duration = 3000) {
                this.show('正在执行 ' + operationName + '...');
                
                let progress = 0;
                const interval = setInterval(() => {
                    progress += 5;
                    if (progress <= 100) {
                        this.updateProgress(progress);
                    } else {
                        clearInterval(interval);
                        this.hide();
                        $.messager.alert('操作完成', operationName + ' 执行成功！', 'info');
                    }
                }, duration / 20);
            }
        };

        // 绑定按钮事件
        $(document).ready(function() {
            // 显示基本加载效果
            $('#showLoading').click(function() {
                LoadingManager.show();
                setTimeout(() => {
                    LoadingManager.hide();
                }, 2000);
            });
            
            // 显示带自定义文字的加载效果
            $('#showLoadingWithText').click(function() {
                LoadingManager.show('数据处理中，请耐心等待...');
                setTimeout(() => {
                    LoadingManager.hide();
                }, 2000);
            });
            
            // 显示进度条加载效果
            $('#showProgressLoading').click(function() {
                LoadingManager.showWithProgress('正在加载数据...');
                
                // 模拟进度更新
                let progress = 0;
                const progressInterval = setInterval(() => {
                    progress += 10;
                    LoadingManager.updateProgress(progress);
                    
                    if (progress >= 100) {
                        clearInterval(progressInterval);
                        setTimeout(() => {
                            LoadingManager.hide();
                        }, 500);
                    }
                }, 300);
            });
            
            // 隐藏加载效果
            $('#hideLoading').click(function() {
                LoadingManager.hide();
            });
            
            // EasyUI 操作演示
            $('#easyuiOperation').click(function() {
                const operation = $('#operationSelect').combobox('getValue');
                const operationNames = {
                    'loadData': '数据加载',
                    'processForm': '表单处理',
                    'ajaxRequest': 'AJAX请求'
                };
                
                LoadingManager.simulateOperation(operationNames[operation], 4000);
            });
            
            // 初始化 EasyUI 组件
            $('#operationSelect').combobox({
                panelHeight: 'auto'
            });
        });

        // 全局AJAX请求拦截，自动显示加载效果
        $(document).ajaxStart(function() {
            LoadingManager.show('请求发送中...');
        });
        
        $(document).ajaxStop(function() {
            LoadingManager.hide();
        });
    </script>
</body>
</html>
